** Figure 7: Impulse response for trades involving access/nonaccess banks

clear

** Loading data
*Include:
*cd // *Your directory path goes here* //
import excel .\Data\GC_DailyAverages_Pseudo.xlsx, firstrow allstring

* Step 1: Organize the data:
gen dateSTATA = date(substr(refdate,1,11),"MDY")
format dateSTATA %td
drop refdate
gen year = year(dateSTATA)
gen month = month(dateSTATA)

destring volweightedrate volsum ecbaccesslender, replace
encode basket, gen(basketcat)
drop basket
label define order  1 ON  2 TN  3 SN
encode term, gen(termcat) label(order)
drop term

keep if country=="DE"

egen panelid = group(basketcat termcat ecbaccesslender)
xtset panelid dateSTATA

* Step 2: Add information on EONIA
* download daily data from, for example, Bloomberg / Thomson Reuters and replace code below:
gen EONIA=0.5 // create pseudodata

* Step 3: Add information on DFR
* download data on the DFR (see e.g.: https://www.ecb.europa.eu/stats/policy_and_exchange_rates/key_ecb_interest_rates/html/index.en.html) and replace code below:
gen DFR=0.5 // create pseudodata

* Step 4: Calculate daily, average GC rate
preserve
sort country dateSTATA
by country dateSTATA: egen meanGCRate = wtmean(volweightedrate), weight(volsum)
keep meanGCRate country dateSTATA
duplicates drop
save .\Data\MeanGCRatesByCountry.dta, replace
restore
merge m:1 dateSTATA country using .\Data\MeanGCRatesByCountry.dta
keep if _merge==3
drop _merge
erase .\Data\MeanGCRatesByCountry.dta

gen GCBelowDep = 0
replace GCBelowDep = 1 if meanGCRate<DFR

* Step 5: Calculate changes:

bysort panelid (dateSTATA): gen delrGC = log(volweightedrate[_n]/volweightedrate[_n-1])
bysort panelid (dateSTATA): gen delrGCtm1 = log(volweightedrate[_n-1]/volweightedrate[_n-2])
bysort panelid (dateSTATA): gen delMMRate = log(EONIA[_n]/EONIA[_n-1])
bysort panelid (dateSTATA): gen delMMRatetm1 = log(EONIA[_n-1]/EONIA[_n-2])
bysort panelid (dateSTATA): gen delMMRatetm2 = log(EONIA[_n-2]/EONIA[_n-3])
bysort panelid (dateSTATA): gen delMMRatetm3 = log(EONIA[_n-3]/EONIA[_n-4])
bysort panelid (dateSTATA): gen delMMRatetm4 = log(EONIA[_n-4]/EONIA[_n-5])
bysort panelid (dateSTATA): gen delMMRatetm5 = log(EONIA[_n-5]/EONIA[_n-6])
bysort panelid (dateSTATA): gen delMMRatetm6 = log(EONIA[_n-6]/EONIA[_n-7])
bysort panelid (dateSTATA): gen delMMRatetm7 = log(EONIA[_n-7]/EONIA[_n-8])
bysort panelid (dateSTATA): gen delMMRatetm8 = log(EONIA[_n-8]/EONIA[_n-9])
bysort panelid (dateSTATA): gen delMMRatetm9 = log(EONIA[_n-9]/EONIA[_n-10])
bysort panelid (dateSTATA): gen delMMRatetm10 = log(EONIA[_n-10]/EONIA[_n-11])
label variable delMMRate    "0"
label variable delMMRatetm1 "-1"
label variable delMMRatetm2 "-2"
label variable delMMRatetm3 "-3"
label variable delMMRatetm4 "-4"
label variable delMMRatetm5 "-5"
label variable delMMRatetm6 "-6"
label variable delMMRatetm7 "-7"
label variable delMMRatetm8 "-8"
label variable delMMRatetm9 "-9"
label variable delMMRatetm10 "-10"

** Create graph:
eststo clear
sort termcat

eststo Access: reghdfe delrGC delMMRate delMMRatet* delrGCtm1 if ecbaccesslender==1 & GCBelowDep==0, absorb(year##month##termcat) vce(robust) nocons 
eststo Nonaccess: reghdfe delrGC delMMRate delMMRatet* delrGCtm1 if ecbaccesslender==0 & GCBelowDep==0, absorb(year##month##termcat) vce(robust) nocons
eststo AccessBel: reghdfe delrGC delMMRate delMMRatet* delrGCtm1 if ecbaccesslender==1 & GCBelowDep==1, absorb(year##month##termcat) vce(robust) nocons 
eststo NoAccessBel: reghdfe delrGC delMMRate delMMRatet* delrGCtm1 if ecbaccesslender==0 & GCBelowDep==1, absorb(year##month##termcat) vce(robust) nocons
coefplot Access Nonaccess, bylabel(GC Rate above Deposit Rate) drop(delrGCtm1) || AccessBel NoAccessBel, drop(delrGCtm1) bylabel(GC Rate below Deposit Rate)||, ylabel(-1(1)2) yscale(range(-1(1)2)) yline(0) vertical legend(cols(2)) scheme(plotplainblind)
